import Vue from 'vue'
import ElementUI from 'element-ui'
import '@/assets/styles/element-theme/index.css'
import VueAreaLinkage from 'vue-area-linkage'
import 'vue-area-linkage/dist/index.css'
import { VueAxios } from '@/utils/request'
import '@/assets/styles/nprogress.less'
import '@/assets/styles/index.less'

Vue.use(ElementUI)
Vue.use(VueAreaLinkage)
Vue.use(VueAxios)

// 触发上级及以上方法
Vue.prototype.$dispatch = function (eventName, value) {
  let parent = this.$parent;
  while (parent) {
    parent.$emit(eventName, value);
    parent = parent.$parent;
  }
}

// 触发下级及以下方法
Vue.prototype.$broadcast = function (eventName, value) {
  let children = this.$children;
  broad(children);
  function broad(children) {
    children.forEach(child => {
      child.$emit(eventName, value);
      if (child.$children) {
        broad(child.$children)
      }
    });
  }
}
